package com.sykj.wangkun.controller;

import com.sykj.bean.sys.SysDept;
import com.sykj.util.reponse.CommonEnum;
import com.sykj.util.reponse.ResultBody;
import com.sykj.wangkun.bean.AdmUser;
import com.sykj.wangkun.service.SysDeptService;
import com.sykj.wangkun.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: SysUserController
 * @Package: com.sykj.wangkun.controller
 * @program: BeautyClub
 * @description: 后台管理员控制层接口
 * @author: Mr.Wang
 * @create: 2020-07-20 09:14
 **/
@CrossOrigin
@RestController
@RequestMapping("/sysuser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysDeptService sysDeptService;
    /**
     * 功能描述:查询后台管理员的信息
     * @author 姓名
     * @date
     */
    @RequestMapping("/sysuser")
    public List<AdmUser> queryall(){
        List<AdmUser> admUserList = sysUserService.queryall();
        return admUserList;
    }

    /**
     * 功能描述:查询所有的部门信息
     * @author 姓名
     * @date
     */
    @RequestMapping("/querydept")
    public List<SysDept> querydept(){
        List<SysDept> list = sysDeptService.list();
        return list;
    }

    /**
     * 功能描述:添加后台管理员信息
     * @author 姓名
     * @date
     */
    @RequestMapping("/addsysuser")
    public ResultBody addsysuser(AdmUser admUser){
        ResultBody addsysuser = sysUserService.addsysuser(admUser);
        return addsysuser;
    }
    /**
     * 功能描述:根据后台管理员id进行查询
     * @author 姓名
     * @date
     */
    @RequestMapping("/queryById")
    public AdmUser queryById(Integer userId){
        AdmUser byId = sysUserService.getById(userId);
        return byId;
    }

    /**
     * 功能描述:根据id 进行修改
     * @author 姓名
     * @date
     */
    @RequestMapping("/updateById")
    public ResultBody updateById(AdmUser admUser){
        sysUserService.updateById(admUser);
        return new ResultBody(CommonEnum.SUCCESS);
    }

    /**
     * 功能描述:删除管理员信息 假删除
     * @author 姓名
     * @date
     */
    @RequestMapping("/updateByisDel")
    public ResultBody updateByisDel(Integer userId){
        sysUserService.updateByisDel(userId);
        return new ResultBody(CommonEnum.SUCCESS);
    }

    /**
     * 功能描述:登录
     * @author 姓名
     * @date
     */
    @RequestMapping("/login")
    public ResultBody login(String account, String password){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token=new UsernamePasswordToken(account,password);
        subject.login(token);

        return new ResultBody(CommonEnum.SUCCESS);
    }


}
